package org.yzh.scheduler.model.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import org.yzh.commons.annotations.Cron;

import java.time.LocalDateTime;

public class ScheduleJobDO {

    @Schema(description = "id")
    private Integer id;
    @Schema(description = "任务名称(接口名)")
    private String jobName;
    @Schema(description = "任务组(系统名)")
    private String jobGroup;

    @NotNull
    @Schema(description = "HttpMethod")
    private String method;
    @URL
    @Length(max = 250)
    @Schema(description = "HttpURL")
    private String url;
    @NotNull
    @Schema(description = "HttpContentType")
    private String contentType;
    @Schema(description = "HttpParameters")
    private String parameters;

    @Cron
    @Length(max = 120)
    @Schema(description = "cron表达式")
    private String cronExpression;
    @Length(max = 250)
    @Schema(description = "任务描述")
    private String description;

    @Schema(description = "是否禁用")
    private Boolean disabled;
    @Schema(description = "修改时间")
    private LocalDateTime updatedAt;
    @Schema(description = "创建时间")
    private LocalDateTime createdAt;

    @Schema(description = "最近一次运行日志")
    private transient JobLogDO jobLog;
    @Schema(description = "任务状态")
    private transient String state;

    public ScheduleJobDO() {
    }

    public ScheduleJobDO(String jobName, String jobGroup) {
        this.jobName = jobName;
        this.jobGroup = jobGroup;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getParameters() {
        return parameters;
    }

    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean getDisabled() {
        return disabled;
    }

    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public JobLogDO getJobLog() {
        return jobLog;
    }

    public void setJobLog(JobLogDO jobLog) {
        this.jobLog = jobLog;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ScheduleJobDO other = (ScheduleJobDO) that;
        return (this.getJobGroup() == null ? other.getJobGroup() == null : this.getJobGroup().equals(other.getJobGroup()))
               && (this.getJobName() == null ? other.getJobName() == null : this.getJobName().equals(other.getJobName()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getJobGroup() == null) ? 0 : getJobGroup().hashCode());
        result = prime * result + ((getJobName() == null) ? 0 : getJobName().hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "ScheduleJobDO{" +
               "id=" + id +
               ", jobName='" + jobName + '\'' +
               ", jobGroup='" + jobGroup + '\'' +
               ", disabled=" + disabled +
               ", cronExpression='" + cronExpression + '\'' +
               ", description='" + description + '\'' +
               ", method='" + method + '\'' +
               ", url='" + url + '\'' +
               ", contentType='" + contentType + '\'' +
               ", parameters='" + parameters + '\'' +
               ", updatedAt=" + updatedAt +
               ", createdAt=" + createdAt +
               ", jobLog=" + jobLog +
               '}';
    }
}